<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>分享页面</title>
    <link rel="stylesheet" th:href="@{/js/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/css/layui-theme-custom.css}"/>
    <link rel="stylesheet" th:href="@{/css/mytest.css}"/>
    <link rel="stylesheet" th:href="@{/css/copyshare.css}"/>
    <script type="text/javascript" charset="utf-8" th:src="@{/js/ueditor.config.js}"></script>
    <script type="text/javascript" charset="utf-8" th:src="@{/js/ueditor.all.min.js}"></script>
    <script type="text/javascript" charset="utf-8" th:src="@{/js/zh-cn.js}"></script>
    <script th:src="@{/js/layui/layui.js}"></script>
    <script type="text/javascript" th:src="@{/js/vue.min.js}"></script>
    <script type="text/javascript" th:src="@{/js/axios.min.js}"></script>
</head>

<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">
            <img th:src="@{/img/logo.png}" width="70px"/> 鲸鱼笔记
        </div>
        <div class="share-link" hidden="hidden"><input id="link" class="link2" value=""></div>
        <textarea id="hidden"></textarea>
        <!-- 头部区域（可配合layui已有的水平导航） -->
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <button class="save" id="save">保存到我的笔记</button>
            </li>

            <li class="layui-nav-item">
                <button class="share" onclick="copyText();">分享</button>
            </li>
        </ul>
    </div>

    <div class="foot">
        <div class="foot1">
            <div class="user-context" id="nickname"></div>
            <div class="share-content" id="sharenotes">
                <div class="content-header" id="noteName"></div>
                <div class="content-content" id="content"></div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['element', 'layer'], function () {
        var element = layui.element;
        var $ = layui.$;
        var layer = layui.layer;
        var token = localStorage.getItem("Token");
        console.log(token);

        var myUrl=localStorage.getItem("myUrl");


        var $_GET = (function () {
            var url = window.document.location.href.toString(); //获取的完整url
            console.log(url)
            $("#link").val(url);
            var u = url.split("?");
            if (typeof (u[1]) == "string") {
                u = u[1].split("&");
                var get = {};
                for (var i in u) {
                    var j = u[i].split("=");
                    get[j[0]] = j[1];
                }
                return get;
            } else {
                return {};
            }

        })();

        var id = $_GET['id'];

        console.log(id);


        $.ajax({
            data: {
                nodeId: id,
            },
            type: 'post',
            url: myUrl+'/note-notes/notes/getNotes',
            success: function (data) {
                console.log(data);
                $('#noteName').text(data.notesName);
                $('#content').text(data.content);
                var userid = data.userId;
                console.log(userid)
                $.ajax({
                    data: {
                        userId: userid,
                    },
                    type: 'post',
                    url: myUrl+'/note-user/user/getShareUser',
                    success: function (data) {
                        $('#nickname').text(data.nickname + "的分享");
                        console.log(data);
                    }
                })
            }

        })

        $('#save').click(function () {

            if (token == null) {
                alert("未登录，请先登录")
                location.href = "http://330e393c.cpolar.io/login/pc_loginPage";
            } else {
                $.ajax({
                    data: {
                        nodeId: id,
                    },
                    type: 'post',
                    url: myUrl+'/note-notes/notes/saveNote?token='+token,
                    success: function (data) {
                        if (data.rs) {
                            alert("保存成功")
                        }
                    }
                })
            }
        })

    });

    function copyText() {
        var text = document.getElementById("link").value;
        var input = document.getElementById("hidden");
        input.value = text; // 修改文本框的内容
        input.select(); // 选中文本
        document.execCommand("copy"); // 执行浏览器复制命令
        alert("复制成功");
    }
</script>
</body>

</html>